{extend name="../../../view/public/base" /}

{block name="css"}
<style>
    body {
        background-color: #F2F2F2;
    }
</style>
{/block}

{block name="body"}
<div style="padding: 20px; background-color: #F2F2F2;">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <form class="layui-form" lay-filter="addForm" autocomplete="off">
<!--                    标识-->
<!--                    <div class="layui-form-item">-->
<!--                        <label class="layui-form-label">标识</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="name" placeholder="请输入标识" class="layui-input" value="{$row.name}">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    &lt;!&ndash;名称&ndash;&gt;-->
<!--                    <div class="layui-form-item">-->
<!--                        <label class="layui-form-label">名称</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="title" placeholder="请输入名称" class="layui-input" value="{$row.title}">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    &lt;!&ndash;描述&ndash;&gt;-->
<!--                    <div class="layui-form-item layui-form-text">-->
<!--                        <label class="layui-form-label">描述</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <script id="description" name="description" type="text/plain" style="width:100%;height:500px;"></script>-->
<!--                            <script>-->
<!--                                //实例化编辑器-->
<!--                                UE.getEditor('description');-->
<!--                                //格式化富文本-->
<!--                                htmlDecode("{$row.description}", 'description')-->
<!--                            </script>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    &lt;!&ndash;配置&ndash;&gt;-->
<!--                    <div class="layui-form-item layui-form-text">-->
<!--                        <label class="layui-form-label">配置</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <script id="config" name="config" type="text/plain" style="width:100%;height:500px;"></script>-->
<!--                            <script>-->
<!--                                //实例化编辑器-->
<!--                                UE.getEditor('config');-->
<!--                                //格式化富文本-->
<!--                                htmlDecode("{$row.config}", 'config')-->
<!--                            </script>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    &lt;!&ndash;作者&ndash;&gt;-->
<!--                    <div class="layui-form-item">-->
<!--                        <label class="layui-form-label">作者</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="author" placeholder="请输入作者" class="layui-input" value="{$row.author}">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    &lt;!&ndash;版本号&ndash;&gt;-->
<!--                    <div class="layui-form-item">-->
<!--                        <label class="layui-form-label">版本号</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="version" placeholder="请输入版本号" class="layui-input" value="{$row.version}">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    &lt;!&ndash;状态:-1=未安装,0=禁用,1=启用&ndash;&gt;-->
<!--                    <div class="layui-form-item">-->
<!--                        <div class="layui-inline">-->
<!--                            <label class="layui-form-label">状态</label>-->
<!--                            <div class="layui-input-block" id="status">-->
<!--                                <select name="status" lay-verify="required">-->
<!--                                    <option value="" >请选择状态</option>-->
<!--                                    <option value="-1" {eq name="$row.status" value="-1"}selected{/eq}>未安装</option>-->
<!--                                    <option value="0" {eq name="$row.status" value="0"}selected{/eq}>禁用</option>-->
<!--                                    <option value="1" {eq name="$row.status" value="1"}selected{/eq}>启用</option>-->
<!--                                </select>-->
<!--                            </div>-->
<!--                        </div>-->
<!--                    </div>-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">价格</label>
                        <div class="layui-input-inline">
                            <input type="number" name="price" placeholder="请输入价钱" class="layui-input" value="{$row.price}">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="submitBtn">立即提交</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

{/block}

{block name="js"}
<script>
    var layer, form, bwajax, upload, $, laydate;

    layui.use(['layer', 'form', 'bwajax', 'upload', 'laydate'], function () {
        layer = layui.layer;
        form = layui.form;
        bwajax = layui.bwajax.instance();
        upload = layui.upload;
        $ = layui.jquery;
        laydate = layui.laydate;

        //TODO 监听提交按钮
        form.on('submit(submitBtn)', function (obj) {
            data = obj.field;

            /*if(!data.name) {layer.msg('标识不能为空', {icon: 2});return false}
            if(!data.title) {layer.msg('名称不能为空', {icon: 2});return false}
            if(!data.status) {layer.msg('状态不能为空', {icon: 2});return false}*/

            if(data.price < 0) {layer.msg('价格不能小于0', {icon: 2});return false}

            //TODO ajax调用后台接口
            bwajax.post("{:Url('edit')}?id={$row.id}", data)
                .then(function (response) {
                    if (response.data.data.errcode === 0) {
                        layer.msg('提交成功', {icon: 1});
                        submitSuccess();
                    } else {
                        layer.msg(response.data.msg, {icon: 2});
                    }
                })

            return false;
        })
    });
</script>
{/block}